import 'package:changxindianzishangwu/dao/report_list_dao.dart';
import 'package:changxindianzishangwu/model/report_list_model.dart';
import 'package:changxindianzishangwu/pages/my/feed_back_page.dart';
import 'package:changxindianzishangwu/pages/my/report_back_page.dart';
import 'package:changxindianzishangwu/util/app_color.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:changxindianzishangwu/util/toast.dart';
import 'package:changxindianzishangwu/util/universal_view.dart';
import 'package:changxindianzishangwu/widget/app_bar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

///好友=》投诉/举报

class ReportPage extends StatefulWidget {
  int type; //1单聊 2群聊
  String objectId; //群组ID或者用户ID
  ReportPage(this.type, this.objectId, {Key key}) : super(key: key);

  @override
  _ReportPageState createState() => _ReportPageState();
}

class _ReportPageState extends State<ReportPage> {
  List<ReportBean> _lists = [];

  @override
  void initState() {
    // TODO: implement initState
    getDataList();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TopAppBar(context, "投诉/举报"),
      body: Container(
        color: AppColor.bg,
        child: CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: Container(
                padding: EdgeInsets.all(width(15)),
                color: Colors.white,
                width: double.infinity,
                child: Text(
                  "请选择投诉该账号的原因：",
                  style: TextStyle(
                      color: AppColor.colorHintText, fontSize: sp(12)),
                ),
              ),
            ),
            SliverList(
              delegate:
                  SliverChildBuilderDelegate((BuildContext content, int index) {
                return _sliverItem(index);
              }, childCount: _lists.length),
            )
          ],
        ),
      ),
    );
  }

  Widget _sliverItem(int index) {
    return InkWell(
      onTap: () {
        Get.to(ReportBackPage(reportBean: _lists[index],objectId: widget.objectId,));
      },
      child: Container(
        color: Colors.white,
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.all(width(15)),
              child: Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Text(
                      _lists[index].reportContent,
                      style: TextStyle(
                          color: AppColor.colorDefaultText, fontSize: sp(15)),
                    ),
                  ),
                  Icon(
                    Icons.arrow_forward_ios,
                    size: 15,
                    color: AppColor.colorHintText,
                  )
                ],
              ),
            ),
            UniversalView().line(),
          ],
        ),
      ),
    );
  }

  void getDataList() async {
    ReportListModel model = await ReportDao.getEmojiList(widget.type);
    if (model.resultCode != 1) {
      toast("获取举报信息失败");
      return;
    }
    if (mounted)
      setState(() {
        _lists.addAll(model.data);
      });
  }
}
